package com.digitalart.section.index
{
	import flash.events.EventDispatcher;
	import com.digitalart.commons.CustomXmlLoader;
	import com.digitalart.commons.CustomEvent;

	public class IndexModel extends EventDispatcher
	{
		public static const PATH:String="xml/index.xml";
		public static const ON_INDEX_MODEL_READY : String = "onDataLoadedComplete";
		
		/**********************************Constructor*************************/
		
		public function IndexModel (){
			super(this);
			
		}
		
		
		/**********************************************************************/
		
		/**********************************Methods*************************/
		
		public function init():void{
			
			var loader : CustomXmlLoader = CustomXmlLoader.getInstance();
			loader.addEventListener(CustomXmlLoader.XML_LOAD_COMPLETE, loadData);
			loader.loadXml(PATH);
		}
		
		private function loadData(event:CustomEvent) : void {
			
			event.target.removeEventListener(CustomXmlLoader.XML_LOAD_COMPLETE, loadData);
			
			var xmlFile:XML = event.data;
			var indexVO:IndexVO = new IndexVO();
			
			indexVO.backgroundPath = xmlFile.assets.background.@src;
			indexVO.underConstructionCopy = xmlFile.copy.underConstruction;
	 
			
			dispatchEvent(new CustomEvent(ON_INDEX_MODEL_READY, indexVO));
		}
	}
}